<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="../github-markdown.css" />
    <link rel="stylesheet" href="../custom.css" />
    <script src="../custom.js"></script>
    <link rel="stylesheet" href="../custom_zh-CN.css" />
    <title>WSL2</title>
  </head>
  <body class="markdown-body">
    <h2>安装</h2>
    <p>以管理员身份运行 PowerShell 脚本：</p>
    <ol>
      <li>
        <p>安装 HyperV 组件</p>
        <pre><code>dism /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
</code></pre>
      </li>
      <li>
        <p>可选：添加系统启动选项</p>
        <div class="editable">
          <pre><code># 降低选择等待时间
bcdedit /timeout 2
# 推荐使用传统菜单（ 不会二次启动 ）
bcdedit /set "{current}" bootmenupolicy legacy

bcdedit /set "{current}" hypervisorlaunchtype off
bcdedit /copy "{current}" /d "HyperV off"
bcdedit /set "{current}" hypervisorlaunchtype auto
bcdedit /copy "{current}" /d "HyperV on"
</code></pre>
        </div>
      </li>
      <li>重启</li>
      <li>
        <a href="ms-windows-store://pdp?mode=mini&productId=9P9TQF7MRM4R"
          >安装或更新 WSL 内核</a
        >
      </li>
      <li>
        可选：<a href="ms-settings:windowsupdate-options">设置自动更新</a>，
        启动“接收其它 Microsoft 产品的更新”。
      </li>
    </ol>
    <h2>使用方法</h2>
    <p>导入 Linux 子系统：</p>
    <div class="editable">
      <pre><code>$vmname = 'alpine'

$fromGzip = Read-Host '下载路径' | Get-Item
$toDir = Read-Host '子系统存储路径' | Get-Item

wsl --import $vmname $toDir $fromGzip
wsl -s $vmname # 设为默认
wsl -d $vmname
</code></pre>
    </div>
    <p>导出备份：</p>
    <div class="editable">
      <pre><code>wsl --export $vmname "$vmname.tar"</code></pre>
    </div>
  </body>
</html>
